// pages/activity/business.js
const appInst = getApp();
import { Activity } from '../../model/activity'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: false,
    date_active: 0,
    data_arr: [],
    sj_msg_id: '',
    sj_msg: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      sj_msg_id: options.id
    })
    this.getWeekDate()
  },
  getWeekDate() {
    const data_arr = appInst.getDateWeek(7)
    this.setData({
      data_arr: data_arr,
    })
    this.getSjMsgInfo()
  },
  // 商家详情
  async getSjMsgInfo(){
    wx.showLoading({
      title: '加载中',
    });
    const res = await Activity.getSjMsgInfo(this.data.sj_msg_id,{week: this.data.data_arr[this.data.date_active][0]})
    this.setData({
      sj_msg: res,
      hidden: true,
    })
    wx.hideLoading()
  },
  openBusiness(e) {
    wx.navigateTo({
      url: './business_info?id='+e.currentTarget.id+'&date='+this.data.data_arr[this.data.date_active][1]+'&week='+this.data.data_arr[this.data.date_active][0]
    })
  },
  openOtherBusiness() {
    wx.navigateTo({
      url: './business_other_info'
    })
  },
  changeState(e) {
    if(this.data.date_active != e.currentTarget.id) {
      this.setData({
        date_active: e.currentTarget.id,
      })
      this.getSjMsgInfo();
    }
  }
})